# # @Time    :2025/4/9 8:14
def inser_sort(alist):
    """插入排序"""
    # 稳定，从后往前挪
    n = len(alist)
    # 外层，从右边无序序列中取出第一个元素，并插入到左边有序序列的适当位置
    for j in range(1, n):
 #       i = j

        #执行从右边的无序序列中取出第一个元素，并插入到左边有序序列的适当位置
        while j > 0:
            if alist[j] < alist[j - 1]:
                alist[j], alist[j - 1] = alist[j - 1], alist[j]
                j -= 1
            else:
                break

if __name__ == '__main__':
    alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
    print(alist)
    inser_sort(alist)
    print(alist)
